/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import View.JFrameCarro;

/**
 *
 * @author Cabral
 */
public class Veiculo {
    private String placa;
    private String marca;
    private String modelo;
    private String cor;
    private String CPF;
    
public Veiculo(){}

public Veiculo(String placa,String marca,String modelo,String cor,String CPF){
    this.placa = placa;
    this.marca = marca;
    this.modelo = modelo;
    this.cor = cor;
    this.CPF = CPF;
}

public void Insere_Veiculo(){
    try {
    //Registra JDBC driver
    Class.forName("com.mysql.jdbc.Driver");
 
    //Abrindo a conexão: ATENÇÃO OS DOIS PARÂMETROS VAZIOS("") 
    //SÃO USUÁRIO E SENHA, RESPECTIVAMENTE.
    Connection conn = DriverManager.getConnection
        ("jdbc:mysql://localhost:3306/"
                + "estacionamento?zeroDateTimeBehavior=convertToNull"
                , "root", "abcd");
    //Executa a query de inserção
    java.sql.Statement st = conn.createStatement();
    st.executeUpdate("INSERT INTO carro (placa,marca,modelo,cor,cpf) VALUES ("
            + this.placa + ",'"
            + this.marca + "','"
            + this.modelo + "','"
            + this.cor + "','"
            + this.CPF + "')");
    
    JOptionPane.showMessageDialog
        (null, java.util.ResourceBundle.getBundle("Bundle")
                .getString("Veiculo Inserido"));
    
} catch (SQLException | ClassNotFoundException e) {
    JOptionPane.showMessageDialog(null,e);
}//Fim try
}

public void Deleta_Veiculo(String placa){
    
    try {
    //Registra JDBC driver
    Class.forName("com.mysql.jdbc.Driver");
 
    //Abrindo a conexão
    Connection conn = DriverManager.getConnection
        ("jdbc:mysql://localhost:3306/estacionamento?zeroDateTimeBehavior"
                + "=convertToNull", "root", "abcd");
 
    //Executa a query de exclusão
    java.sql.Statement st = conn.createStatement();
    st.executeUpdate("DELETE FROM Carro WHERE placa='" + placa + "'");
    
    JOptionPane.showMessageDialog
        (null, java.util.ResourceBundle.getBundle
        ("Bundle").getString("Veículo excluído"));
    
} catch (SQLException | ClassNotFoundException e) {
    JOptionPane.showMessageDialog(null, e);
}//Fim try

}
        
}
